/**
 * Project  : Looker
 * Package  : net.freestu.looker.util
 * File     : Html.java
 * Author   : solosky < solosky772@qq.com >
 * Date     : Aug 27, 2009
 * Modified : Aug 27, 2009
 * License  : Apache License 2.0 
 */
package net.freestu.looker.util;


/**
 *  处理HTML和URL相关方法
 */
public class HtmlUtils
{
	/**
	 * 去除所有的HTML标记
	 */
	public static String stripTags(String  htmlCode)
    {
		if (htmlCode==null)
			return null;
         htmlCode = htmlCode.replaceAll("\t" , "").replaceAll("\n" , "").replaceAll(" " , "");
         htmlCode = htmlCode.replaceAll("<script(.[^(</script>)]*)</script>" , "");
         htmlCode = htmlCode.replaceAll("<(.[^>]*)>" , "");
         htmlCode = htmlCode.replaceAll("&nbsp;" , "");
         return htmlCode;
    }
	
	/**
	 * 转义HTML网页中存在的'"`\等对SQL语句有含义的字符
	 */
	public static String sqlSafe(String str)
	{
		if (str==null)
			return null;
		/*str = str.replaceAll("`", "\\`");
		str = str.replaceAll("\"", "\\\"");
		str = str.replaceAll("'", "\\\\'"); // 处理'
		str = str.replaceAll("\\\\", "\\\\\\\\");
		*/
		  String newKey=str.replaceAll("\\\\","\\\\\\\\");//处理\插入
          newKey=newKey.replaceAll("'","\\\\'");   //处理'插入防止SQL注入
          newKey=newKey.replaceAll("\"","\\\\\"");

		return newKey;
	}
	
	
	public static void main(String[]args){
		String html = "<html><head><TITLE>成都理工大学</TITLE><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"Author\" content=\"feng xianwen\"><link rel=\"stylesheet\" type=\"text/css\" href=\"/cdut/css/main.css\"/><script src=\"/cdut/js/common.js\"></script><script src=\"/cdut/js/navi.js\"></script></head><body leftmargin=20 topmargin=20 bgcolor=#eeeeee><table bgcolor=#666666 width=100% cellpadding=10 cellspacing=1 border=0><tr bgcolor=#ffffff><td><P class=MsoNormal style=\"MARGIN: 0cm -2.9pt 0pt 0cm; LINE-HEIGHT: 150%; TEXT-ALIGN: center\" align=center><B style=\"mso-bidi-font-weight: normal\"><SPAN lang=EN-US style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"><?xml:namespace prefix = o ns = \"urn:schemas-microsoft-com:office:office\" /><o:p>&nbsp;</o:p></SPAN></B></P><P class=MsoNormal style=\"MARGIN: 0cm -2.9pt 0pt 0cm; LINE-HEIGHT: 150%; TEXT-ALIGN: center\" align=center><B style=\"mso-bidi-font-weight: normal\"><SPAN style=\"FONT-SIZE: 15pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">我校获“成都市第二届大学生普通物理知识竞赛”第四名<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></B></P><P class=MsoNormal style=\"MARGIN: 0cm -2.9pt 0pt 0cm; LINE-HEIGHT: 150%; TEXT-ALIGN: center\" align=center><B style=\"mso-bidi-font-weight: normal\"><SPAN lang=EN-US style=\"FONT-SIZE: 15pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"><o:p>&nbsp;</o:p></SPAN></B></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><?xml:namespace prefix = st1 ns = \"urn:schemas-microsoft-com:office:smarttags\" /><st1:chsdate w:st=\"on\" IsROCDate=\"False\" IsLunarDate=\"False\" Day=\"16\" Month=\"5\" Year=\"2009\"><SPAN lang=EN-US style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">2009</SPAN><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">年<FONT size=3><FONT face=宋体><SPAN lang=EN-US>5</SPAN>月<SPAN lang=EN-US>16</SPAN>日</FONT></FONT></SPAN></st1:chsdate><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">，成都市第二届大学生普通物理知识竞赛决赛暨颁奖典礼在四川大学成功举行。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><st1:chsdate w:st=\"on\" IsROCDate=\"False\" IsLunarDate=\"False\" Day=\"18\" Month=\"4\" Year=\"2009\"><SPAN lang=EN-US style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">2009</SPAN><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">年<FONT size=3><FONT face=宋体><SPAN lang=EN-US>4</SPAN>月<SPAN lang=EN-US>18</SPAN>日</FONT></FONT></SPAN></st1:chsdate><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">，成都市第二届大学生普通物理知识竞赛初赛同时在我校和四川大学，电子科技大学，西南交通大学，四川师范大学，西华大学，成都信息工程学院拉开战幕，共有来自各高校的近八千名学子积极参加了初赛。经过同学们激烈角逐和老师的精心筛选，上述七大高校各选出<FONT size=3><FONT face=宋体><SPAN lang=EN-US>3</SPAN>人组成代表队参加最终决赛。我校由信息工程学院物理系主任张正阶教授和物理系副主任赵晓凤老师等带队，<SPAN lang=EN-US>07</SPAN>级应用物理专业的陈楚翘，岳凌，李彬代表我校参赛。<SPAN lang=EN-US><o:p></o:p></SPAN></FONT></FONT></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><st1:chsdate w:st=\"on\" IsROCDate=\"False\" IsLunarDate=\"False\" Day=\"16\" Month=\"5\" Year=\"2009\"><SPAN lang=EN-US style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">5</SPAN><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">月<FONT size=3><FONT face=宋体><SPAN lang=EN-US>16</SPAN>日</FONT></FONT></SPAN></st1:chsdate><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">下午<FONT size=3><FONT face=宋体><SPAN lang=EN-US>2</SPAN>：<SPAN lang=EN-US>30</SPAN>，四川大学艺术学院小剧场气氛热烈。四川大学教授高洁院士，成都市物理学会会长及各高校物理学教授出席了决赛。高洁院士深入浅出地为同学们讲解了很多物理学中有趣的研究成果，并鼓励同学们积极进行物理科学研究，为物理学的发展作出贡献。在场的同学都倍受鼓舞。<SPAN lang=EN-US><o:p></o:p></SPAN></FONT></FONT></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; LINE-HEIGHT: 200%; TEXT-ALIGN: left\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">决赛在精彩的文艺节目后正式拉开战幕。比赛采用知识竞答的形式，分为必答题、选答题和抢答题三环节。各环节题目既充满趣味又富于物理知识。例如“请用物理知识解释暖水瓶为何保温”等，寓教于乐。在激烈而紧张的比赛过程中，各代表队选手们快速反应、从容应答，频频赢得评委老师及观众的好评。经过约半小时的比赛。最终西南交通大学代表队以稳定的发挥摘得桂冠，我校代表队获得第四名，同时获得“最佳团队协作奖”。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN lang=EN-US style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"><o:p></o:p></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">本届普通物理知识竞赛不仅为同学们提供了一个展现自我的平台，更充分地激发了同学们的科学研究精神，鼓舞了一大批有志于物理知识研究的同学，同时也加强了各高校之间的联系，可谓一举多得。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\">我校信息工程学院承办了理工大学赛区的比赛，承办方精心组织，同学们勇跃参与。因为有学院的大力支持，老师们的耐心指导，我校同学们取得了佳绩。</SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"></SPAN>&nbsp;</P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"><IMG id=uploadedFile alt=uf1242874714424.jpg src=\"/cdut/uploadfiles/uf1242874714424.jpg\" ufurl=\"/cdut/uploadfiles/uf1242874714424.jpg\"></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"></SPAN>&nbsp;</P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"><SPAN style=\"FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA\"><STRONG>附：我校获奖情况</STRONG></SPAN></SPAN></P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"></SPAN>&nbsp;</P><P class=MsoNormal style=\"MARGIN: 0cm 6pt 0pt 0cm; TEXT-INDENT: 24pt; LINE-HEIGHT: 200%; TEXT-ALIGN: left; mso-char-indent-count: 2.0\" align=left><SPAN style=\"FONT-SIZE: 12pt; LINE-HEIGHT: 200%; FONT-FAMILY: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast\"><A id=uploadedFile href=\"/cdut/downloadServlet?url=/cdut/uploadfiles/uf1242874916307.doc&amp;label=uf1242874916307.doc\" target=_blank ufurl=\"/cdut/uploadfiles/uf1242874916307.doc\" alt=\"uf1242874916307.doc\"><IMG src=\"/cdutadmin/editor/images/doc.gif\" border=0>请点击此处下载</A><SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P></td></tr></table><br><br><br><table width=100% cellpadding=0 cellspacing=0 border=0><tr><td><P>学校地址：成都市成华区二仙桥东三路1号 邮政编码：610059 传真：028-84077163<BR>成都理工大学网络教育学院网络信息中心&nbsp;© 2004<BR><FONT size=2>蜀ICP备05026980号</FONT></P></td><td align=right valign=middle>由<font color=blue>宣传部</font>创建于2009/05/21　共访问 717 次　　[ <a class=news href=\"#\" onclick=\"window.close();\">关闭窗口</a> ]</td></tr></table></body></html>";
		//String [] retains = "p,br,img".split(",");
		System.out.println(HtmlUtils.stripTags(html));
	}

}
